package com.gilight.base.jpay;

import com.alibaba.fastjson.JSONObject;
import com.github.binarywang.wxpay.bean.request.WxPayOrderReverseRequest;
import com.jeequan.jeepay.Jeepay;
import com.jeequan.jeepay.JeepayClient;
import com.jeequan.jeepay.exception.JeepayException;
import com.jeequan.jeepay.model.DivisionReceiverBindReqModel;
import com.jeequan.jeepay.model.PayOrderCreateReqModel;
import com.jeequan.jeepay.model.PayOrderDivisionExecReqModel;
import com.jeequan.jeepay.request.DivisionReceiverBindRequest;
import com.jeequan.jeepay.request.PayOrderCreateRequest;
import com.jeequan.jeepay.request.PayOrderDivisionExecRequest;
import com.jeequan.jeepay.response.PayOrderCreateResponse;
import com.jeequan.jeepay.response.PayOrderDivisionExecResponse;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

public class PayTest {

    public static void bindRevicer(){
        DivisionReceiverBindRequest divisionReceiverBindRequest = new DivisionReceiverBindRequest();
        DivisionReceiverBindReqModel divisionReceiverBindReqModel = new DivisionReceiverBindReqModel();
        divisionReceiverBindReqModel.setMchNo("M1642211795"); // 商户号
        divisionReceiverBindReqModel.setIfCode("wxpay");
        divisionReceiverBindReqModel.setReceiverAlias("李珂");

        divisionReceiverBindReqModel.setAppId("6203730ae4b0f51cf6f83657");
    }
    public static void payD(){
        PayOrderDivisionExecRequest payOrderDivisionExecRequest = new PayOrderDivisionExecRequest();
        PayOrderDivisionExecReqModel payOrderDivisionExecReqModel = new PayOrderDivisionExecReqModel();
        payOrderDivisionExecRequest.setBizModel(payOrderDivisionExecReqModel);
        Byte divisionMode = 1;
        payOrderDivisionExecReqModel.setMchNo("M1642211795"); // 商户号
        payOrderDivisionExecReqModel.setPayOrderId("P1497829212655599618");
        payOrderDivisionExecReqModel.setAppId("6203730ae4b0f51cf6f83657");
        //payOrderDivisionExecReqModel.setMchOrderNo("11012022021501261001");
        payOrderDivisionExecReqModel.setUseSysAutoDivisionReceivers(divisionMode);
        JeepayClient jeepayClient = new JeepayClient("http://localhost:9216",
                "bffCbtDNMYXbuN5WYGja2MDpmrL98VXDzOCXFBz2JUCRLgFvTyi6MvCRI87rkmSnmNsiwgcWRQOkORvMaLOG1aqSuIzCnTpb19PvfNmU3E2vg3RUfqbwINvJ4UNlHBas");

        try {
            PayOrderDivisionExecResponse response = jeepayClient.execute(payOrderDivisionExecRequest);
            if(response.getCode() != 0){
                System.out.println(response.getMsg());
            }
        } catch (JeepayException e) {
            e.printStackTrace();
        }
    }


    public static void main(String [] args){
        payD();
        if(1==1){
            return;
        }
        // 创建客户端
        //获取请求参数
        Long amount = 1L;
        String mchOrderNo = "M1638152062128";
        String wayCode = "WX_LITE";

        Byte divisionMode = 0;
        String orderTitle = "海南洋果";



        // 前端明确了支付参数的类型 payDataType
        //String payDataType = "codeImgUrl";
        String payDataType = "wxapp";
        String authCode = "";


        PayOrderCreateRequest request = new PayOrderCreateRequest();
        PayOrderCreateReqModel model = new PayOrderCreateReqModel();
        request.setBizModel(model);

        model.setMchNo("M1642211795"); // 商户号
        model.setAppId("6203730ae4b0f51cf6f83657");
        model.setMchOrderNo(mchOrderNo);
        model.setWayCode(wayCode);
        model.setAmount(amount);
        model.setCurrency("CNY");
        model.setClientIp("192.168.30.106");
        model.setSubject(orderTitle + "线下扫码支付");
        model.setBody(orderTitle + "线下扫码支付");
        model.setNotifyUrl("https://www.atomise.cn/api/anon/paytestNotify/payOrder"); //回调地址
        model.setDivisionMode(divisionMode); //分账模式

        //设置扩展参数
        JSONObject extParams = new JSONObject();
        if(StringUtils.isNotEmpty(payDataType)) {
            extParams.put("payDataType", payDataType.trim());
        }
        if(StringUtils.isNotEmpty(authCode)) {
            extParams.put("authCode", authCode.trim());
        }
        extParams.put("sub_openid","oPE1O4wxw1rNuEQTZ1-v0y0nx-3g");
        extParams.put("openid","oPE1O4wxw1rNuEQTZ1-v0y0nx-3g");
        model.setChannelExtra(extParams.toString());

        JeepayClient jeepayClient = new JeepayClient("http://localhost:9216", "bffCbtDNMYXbuN5WYGja2MDpmrL98VXDzOCXFBz2JUCRLgFvTyi6MvCRI87rkmSnmNsiwgcWRQOkORvMaLOG1aqSuIzCnTpb19PvfNmU3E2vg3RUfqbwINvJ4UNlHBas");
        try {
            PayOrderCreateResponse response = jeepayClient.execute(request);
            if(response.getCode() != 0){
                System.out.println(response.getMsg());
            }
            System.out.println(response.get());
        } catch (JeepayException e) {
            e.printStackTrace();
        }
    }

}
